import { api } from '../utils/apiWrapper.js'
// 获取项目实施周期列表
export function getProjectScheduleList(params) {
  return api.get('/api/data/project_schedule', params)
}


// 获取单个项目实施周期
export function getProjectScheduleById(id) {
  return api.get(`/api/data/project_schedule/${id}`)
}
export async function getProjectScheduleListByProjectId(projectId) {
  let params = { page: 1, pageSize: 100, where: { project_id: projectId } }
  const res = await getProjectScheduleList(params)
 
  const data = res.records.filter(item => item.project_id === projectId).sort((a, b) => {
    const getCodeNumber = code => parseFloat(code.replace('PL', ''));
    return getCodeNumber(a.phase_code) - getCodeNumber(b.phase_code);
  });
  console.log("datareturn",data)
  return data;
}

// 创建项目实施周期
export function createProjectSchedule(data) {
  return api.projectSchedule.create(data)
}

// 更新项目实施周期
export function updateProjectSchedule(id, data) {
  return api.projectSchedule.update(id, data)
}

// 删除项目实施周期
export function deleteProjectSchedule(id) {
  return api.delete(`/api/data/project_schedule/${id}`)
} 